//
//  UIView+Addition.m
//
//  i love nancy.
//  Created by starfish on 15/9/2.
//  Copyright (c) 2015年 小R. All rights reserved.
//

#import "UIView+Addition.h"
#import "Define.h"

@implementation UIView (Addition)
//取得view宽/高
- (CGFloat)width {
    return self.frame.size.width;
}
- (CGFloat)height {
    return self.frame.size.height;
}

//取得view的上/下/左/右偏移
- (CGFloat)top {
    return self.frame.origin.y;
}
- (CGFloat)bottom {
    return self.frame.origin.y + self.frame.size.height;
}
- (CGFloat)left {
    return self.frame.origin.x;
}
- (CGFloat)right {
    return self.frame.origin.x + self.frame.size.width;
}

//取得view的中心x/y坐标
- (CGFloat)centerX{
    return self.frame.origin.x + self.frame.size.width / 2;
}
- (CGFloat)centerY{
    return self.frame.origin.y + self.frame.size.height / 2;
}

//设置view居中
- (void)setCenterX{
    CGRect frame = self.frame;
    frame.origin.x = ScreenWidth / 2 - self.width / 2;
    self.frame = frame;
}
- (void)setCenter{
    CGRect frame = self.frame;
    frame.origin.x = ScreenWidth / 2 - self.width / 2;
    frame.origin.y = ScreenHeight / 2 - self.height / 2;
    self.frame = frame;
}

//设置宽/高/x/y
- (void)setWidth:(CGFloat)width {
    CGRect frame = self.frame;
    frame.size.width = width;
    self.frame = frame;
}
- (void)setHeight:(CGFloat)height {
    CGRect frame = self.frame;
    frame.size.height = height;
    self.frame = frame;
}
- (void)setXOffset:(CGFloat)x {
    CGRect frame = self.frame;
    frame.origin.x = x;
    self.frame = frame;
}
- (void)setYOffset:(CGFloat)y {
    CGRect frame = self.frame;
    frame.origin.y = y;
    self.frame = frame;
}

//设置Origin
- (void)setOrigin:(CGPoint)origin {
    CGRect frame = self.frame;
    frame.origin = origin;
    self.frame = frame;
}

//设置size
- (void)setSize:(CGSize)size {
    CGRect frame = self.frame;
    frame.size = size;
    self.frame = frame;
}

@end
